package savantConn;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;

public class SolrTool {

  public void indexSearcherSolrTest01() throws Exception {
    //1. 创建 solrServer对象
    HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/collection1");

    //2. 执行查询
    //SolrQuery : solr的查询对象
    SolrQuery solrQuery = new SolrQuery("*:*");
    QueryResponse response = solrServer.query(solrQuery);

    //3. 获取数据
    SolrDocumentList documentList = response.getResults();
    for (SolrDocument document : documentList) {
      String id = (String) document.get("id");
      String title = (String) document.get("title");
      String content = (String) document.get("content");
      String url = (String) document.get("url");

      System.out.println("id " + id + " title" + title + " content" + content + " url" + url);

    }
  }
}
